<template>
	<view>
		<view class="nav-b u-border-top u-rela" :style="{ padding: pd + 'rpx' }">
			<view class="u-flex" :class="'u-flex-' + num">
				<view class="m-flex-y u-flex-center u-flex-items-center u-flex-1" v-for="(item, index) in list" :key="index" @click="requestStatus ? getzuo(index) : ''">
					<u-icon :name="item.icon" customPrefix="master" :size="item.size" :color="index == 1 && item.text == '已收藏' ? '#dbb07b' : ''"></u-icon>
					<!-- <u-icon name="dingwei" customPrefix="master" size="18"></u-icon> -->
					<view :class="index == 1 && item.text == '已收藏' ? 'c9' : ''">{{ item.text }}</view>
					<!-- <view class="">{{item.text}}</view> -->
				</view>
			</view>

			<view class="u-flex" :class="'u-flex-' + (12 - num)">
				<view
					class="btn-f u-flex-1 u-font-30"
					:style="{
						backgroundColor: item.bgColor,
						color: item.color,
						margin: item.mg + 'rpx',
						borderRadius: item.br + 'rpx',
						textAlign: 'center',
						lineHeight: 100 - item.mg * 2 + 'rpx'
					}"
					v-for="(item, index) in btList"
					:key="index"
					@click="requestStatus ? getg(index) : ''"
				>
					{{ item.text }}
				</view>
			</view>
			<view class="u-abso boxhu" v-if="rooms.commissiontext" @click="getda">{{ rooms.commissiontext }}</view>
		</view>
		<u-toast ref="uToast"></u-toast>
		<u-datetime-picker :show="show" v-model="value1" mode="date" :closeOnClickOverlay="true" @close="close" @confirm="confirm" @cancel="cancel"></u-datetime-picker>
	</view>
</template>

<script>
export default {
	name: 'nav-b',
	data() {
		return {
			data: [],
			type: 1,
			value1: Number(new Date()),
			show: false
		};
	},
	props: {
		list: {
			type: Array,
			default: () => []
		},
		btList: {
			type: Array,
			default: () => []
		},
		num: {
			type: Number,
			default: 5
		},
		pd: {
			type: Number,
			default: 0
		},
		phone: {
			type: String,
			default: ''
		},
		idd: {
			type: Number,
			default: null
		},
		rooms: {
			type: Object,
			default: {}
		}
	},
	methods: {
		getda() {
			this.$emit('getda');
		},
		async getzuo(index) {
			if (!(await this.getMobile())) {
				return;
			}
			this.requestStatus = false;
			switch (index) {
				case 0:
					let list = [];
					if (uni.getStorageSync('xinfang')) {
						list = JSON.parse(uni.getStorageSync('xinfang'));
					}
					let show = true;
					let that = this;
					if (list.length) {
						list.map((p, i) => {
							if (p.id == this.rooms.id) {
								show = false;
								uni.showModal({
									content: '你已添加,是否前往对比列表',
									success(res) {
										if (res.confirm) {
											that.nextNav('/pages/room/comparison?type=0');
											that.requestStatus = true;
										}
										if (res.cancel) {
											uni.$u.toast('你取消了前往列表页面');
											that.requestStatus = true;
										}
									}
								});
							}
						});
					}
					if (!show) return;
					list.push(this.rooms);
					uni.setStorageSync('xinfang', JSON.stringify(list));
					this.nextNav('comparison?type=0');
					break;
				case 1:
					// 收藏
					let followpropertie = await this.require('followproperties', {
						id: this.idd,
						type: this.list[1].text === '已收藏' ? 1 : 0,
						token: JSON.parse(uni.getStorageSync('userInfo')).token
					});
					if (followpropertie) {
						this.$emit('getchong', this.idd);
					}
					break;
				case 2:
					console.log(this.phone);
					if (!this.phone) return;
					uni.makePhoneCall({
						phoneNumber: this.phone + '' //仅为示例
					});
					break;
				default:
					uni.showModal({
						content: '暂无功能'
					});
					break;
			}
			this.requestStatus = true;
		},
		async getg(index) {
			if (!(await this.getMobile())) {
				return;
			}
			this.requestStatus = false;
			switch (index) {
				case 0:
					if (this.rooms.fczj_user_id == uni.getStorageSync('userId')) {
						return this.$u.toast('不能给自己聊天');
					}
					this.nextNav('/pages/news/xiaoxi?id=' + this.rooms.fczj_user_id);
					break;
				case 1:
					let data = {};
					data.id = this.idd;
					data.name = this.rooms.name;
					uni.setStorageSync('recommend', JSON.stringify(data));
					uni.switchTab({
						url: '/pages/tabbar/recommend'
					});
					break;
				default:
					break;
			}
			this.requestStatus = true;
		},
		close() {
			this.show = false;
			this.$emit('getg', 0);
		},
		cancel() {
			this.show = false;
			this.$emit('getg', 0);
		},
		async confirm(e) {
			console.log(e.value);
			this.time = e.value;
			this.show = false;
			this.$emit('getg', 0);
			let res = await this.require('yuyuekanfang', {
				id: this.idd,
				token: JSON.parse(uni.getStorageSync('userInfo')).token,
				date: e.value
			});
			if (res) {
				uni.$u.toast('预约成功');
			}
		}
	}
};
</script>

<style lang="scss" scoped>
.c9 {
	color: #dbb07b;
}

.boxhu {
	top: -60rpx;
	right: 10rpx;
	padding: 10rpx;
	background-color: #ec6941;
	color: #fff;
	text-align: center;
	border-radius: 10rpx;
}
</style>
